home *** CD-ROM | disk | FTP | other *** search
/ Magnum One / Magnum One (Mid-American Digital) (Disc Manufacturing).iso / d17 / lptcom02.arc / LPTCOM02.ASM < prev    next >
Assembly Source File  |  1988-04-19  |  6KB  |  217 lines

  1.     PAGE    60, 80
  2. TITLE    LPTCOM    15-APR-88    XON/XOFF Printer Interface on COM
  3.  
  4. ;-----------------------------------------------------------------------|
  5. ;                                    |
  6. ;    XON/XOFF Printer Interface                    |
  7. ;        Installed as "terminate and stay resident" program    |
  8. ;                                    |
  9. ;-----------------------------------------------------------------------|
  10. ;    REVISION HISTORY                        |
  11. ;                                    |
  12. ; Number    DD-MMM-YY        WHO            WHY        |
  13. ;-------|---------------|-----------------------|-----------------------|
  14. ; 0.1    |   01-Apr-88   | Frank Waldner        | Initial release    |
  15. ; 0.2    |   19 Apr 88    | David Kirschbaum    | Install check        |
  16. ;    |        | Toad Hall        | (marked with TH)    |
  17. ;    |        | kirsch@braggvax.ARPA    |            |
  18. ;-----------------------------------------------------------------------|
  19.  
  20. COM1    EQU    03F8H            ; Base address COM1
  21. COM2    EQU    02F8H            ; Base address COM2
  22. COMport    EQU    COM1             ; Use COM1
  23.  
  24. RBRport    EQU    COMport            ; Receiver Buffer Register    xx8
  25. IERport    EQU    COMport+1        ; Interrupt Enable Register    xx9
  26. IIRport    EQU    COMport+2        ; Interrupt ID Register        xxA
  27. MCRport    EQU    COMport+4        ; Modem Control Register    xxC
  28. LSRport    EQU    COMport+5        ; Line Status Register        xxD
  29. MSRport    EQU    COMport+6        ; Modem Status Register        xxE
  30. THRport EQU    RBRport            ; Transmit Holding Register    xx8
  31.  
  32. RBF    EQU    1            ; Receive Buffer Full
  33. THRE    EQU    20H            ; Transmit Holding Register Empty
  34.  
  35. XOFF    EQU    'S' - 40H
  36. XON    EQU    'Q' - 40H
  37.  
  38. CR    EQU    0DH
  39. LF    EQU    0AH
  40.  
  41. ;-----------------------------------------------------------------------|
  42. ;    The Usual Stuff                            |
  43. ;-----------------------------------------------------------------------|
  44.  
  45. cGroup    Group    Code
  46.  
  47. Code    Segment Public 'Code'
  48.  
  49.     Assume    CS:Code, DS:Code, ES:Code, SS:Code
  50.  
  51.     Org    100H
  52.  
  53. LPTCOM:
  54.     JMP    Install             ; install traps
  55.  
  56.     PAGE
  57. ;-----------------------------------------------------------------------|
  58. ;    Printer interrupt handler                    |
  59. ;                                    |
  60. ;    ENTRY :    as for printer interrupt (INT 17H)            |
  61. ;                                    |
  62. ;    (AH)=0    Print character in AL   on Err    AH = 1            | 
  63. ;    (AH)=1    Init printer port        AH = Printer Status    | 
  64. ;    (AH)=2    Read printer status        AH = Printer Status    | 
  65. ;    (AX)='TO' Check residency [TH]                    |
  66. ;                                    |
  67. ;    (DX) = Printer number (0,1,2,etc.)                |
  68. ;                                    |
  69. ;    EXIT :    ditto                            |
  70. ;    IF checking residency, exit DX='TO', AX='AD',            |
  71. ;                    BL=COMport (ASCII) [TH]        |
  72. ;                                    |
  73. ;-----------------------------------------------------------------------|
  74.  
  75. Handler    Proc    Far
  76.  
  77.     STI
  78.  
  79.     cmp    ax,'TO'            ;TH testing residency?
  80.     jne    Hand0            ;TH nope
  81.     or    dx,dx            ;TH double-check
  82.     jne    Hand0            ;TH nope
  83.     mov    dx,ax            ;TH return dx='TO' (unlikely)
  84.     mov    ax,'AD'            ;TH really unlikely
  85.     mov    bl,'2'-((COMport-COM2)/100H) ;TH return port installed
  86.     iret                ;TH return to our install process
  87.  
  88. Hand0:                    ;TH
  89.     TEST    AH,AH            ; output request ??
  90.     JNZ    Hand3            ; if NZ: return status
  91.  
  92. Hand1:
  93.     PUSH    BX            ; (+1) save
  94.     PUSH    DX            ; (+2)
  95.     MOV    BL,AL            ; save char
  96. Hand1a:
  97.     MOV    DX,LSRport
  98.  
  99. Hand2:
  100.     IN    AL,DX            ; get line status
  101.     TEST    AL,RBF            ; receive buffer full ?
  102.     JZ    Hand2a            ; if z, no
  103.  
  104.     MOV    DX,RBRport        ; else point to RB port
  105.     IN    AL,DX            ; get char
  106.     AND    AL,7FH            ; filter to 7 bits
  107.  
  108.     CMP    AL,XOFF            ; was XOFF received ?
  109.     JNE    Hand1a            ; if ne, no reason to stop
  110. Xpause:
  111.     MOV    DX,LSRport        ; point to LS port
  112. Xwait:
  113.     IN    AL,DX            ; get line status
  114.     TEST    AL,RBF            ; receive buffer full ?
  115.     JZ    Xwait            ; if z, no, wait some more
  116.  
  117.     MOV    DX,RBRport        ; point to RB port
  118.     IN    AL,DX            ; get char
  119.     AND    AL,7FH            ; filter to 7 bits
  120.     CMP    AL,XON            ; was XON received ?
  121.     JNE    Xpause            ; if ne, something else
  122.     JMP    Hand1a            ; try again
  123. Hand2a:
  124.     TEST    AL,THRE            ; transmit holding register empty ??
  125.     JZ    Hand2            ; if Z: uart not ready yet, loop
  126.  
  127.     MOV    AL,BL
  128.     MOV    DX,THRport        ; transmit port
  129.     OUT    DX,AL            ; transmit
  130.  
  131.     POP    DX            ; (+1) restore
  132.     POP    BX            ; (+0)
  133.  
  134. Hand3:
  135.     MOV    AH,90H
  136.     IRET
  137.  
  138. Handler    EndP
  139.  
  140.     PAGE
  141. ;-----------------------------------------------------------------------|
  142. ;    XON/XOFF Printer Interface                    |
  143. ;                                    |
  144. ;    ENTRY :    normal COM program entry                |
  145. ;                                    |
  146. ;    EXIT :    Terminate / Stay Resident                |
  147. ;                                    |
  148. ;-----------------------------------------------------------------------|
  149.  
  150. Install    Proc    Near
  151.  
  152. ;Toad Hall: first see if we're already installed.  Since normal
  153. ;Int 17H services are only AH=0..2, nothing horrible should happen
  154. ;if we are NOT installed.
  155.     xor    dx,dx            ;TH clear DX (part of test)
  156.     mov    ax,'TO'            ;TH do a residency test
  157.     int    17H            ;TH with Int 17H
  158.     cmp    dx,'TO'            ;TH are we resident?
  159.     jne    Install1        ;TH nope, continue
  160.     cmp    ax,'AD'            ;TH doublecheck
  161.     jne    Install1        ;TH nope, continue
  162.     cmp    bl,'2'-((COMport-COM2)/100H) ;TH same as our port?
  163.     je    Installed        ;TH "Sorry, Dave, I can't do that"
  164.  
  165. Install1:                ;TH
  166.     MOV    DX,Offset Handler    ; first take over INT 17 vector
  167.     MOV    AX,2517H
  168.     INT    21H
  169.  
  170.     CLI
  171.  
  172.     MOV    DX,MCRport        ; get status of MCR
  173.     IN    AL,DX
  174.     OR    AL,0FH            ; set DTR, RTS, OUT1, OUT2
  175.     OUT    DX,AL            ; init MCR
  176.  
  177.     MOV    DX,LSRport        ; clear pending status
  178.     IN    AL,DX
  179.     MOV    DX,RBRport
  180.     IN    AL,DX
  181.     MOV    DX,IIRport
  182.     IN    AL,DX
  183.     MOV    DX,MSRport
  184.     IN    AL,DX
  185.  
  186.     STI
  187.  
  188.     MOV    AH,09            ; DOS9 = Print string
  189.     MOV    DX,Offset Insmsg    ; DS:DX -> message
  190.     INT    21H            ; DOSint
  191.  
  192.     MOV    DX,Offset Install    ; DS:DX -> end of "keep" area
  193.     INT    27H            ; terminate / stay resident
  194.  
  195. Installed:                ;TH
  196.     mov    al,bl            ;TH keep ASCII port nr in AL
  197.     mov    inport,al        ;TH stuff ASCII port nr in string
  198.     mov    dx,offset Resident    ;TH 'Already installed'
  199.     mov    ah,9            ;TH display message
  200.     int    21H
  201.     mov    ah,4CH            ;TH show we failed
  202.     int    21H            ;TH terminate
  203.  
  204. Install    EndP
  205.  
  206. Insmsg    DB    CR,LF,'LPT: redirected to COM'
  207.     DB    '2'-((COMport-COM2)/100H)
  208.     DB    ':',CR,LF,'$'
  209.  
  210. Resident db    CR,LF,'LPTCOM already installed on port '    ;TH
  211. inport    db    '%!'                ;TH stuff port nr here
  212.     db    CR,LF,'Aborting, no action.$'    ;TH
  213.  
  214. Code    EndS
  215.  
  216.     END    LPTCOM            ; of LPTCOM
  217.